package com.custom.util

import android.content.Context
import android.content.SharedPreferences

/**
 * 下面是--> ShardPreference工具类
 */
private var sp: SharedPreferences = MiApplication.context.getSharedPreferences("mi.cache", Context.MODE_PRIVATE)
private var ed: SharedPreferences.Editor = sp.edit()

//        Boolean数据
fun putBoolean(key: String, value: Boolean) {
    ed.putBoolean(key, value)
    ed.commit()
}

//        默认 false
fun getBoolean(key: String): Boolean {
    return sp.getBoolean(key, false)
}

//        String数据
fun putString(key: String, value: String) {
    ed.putString(key, value)
    ed.commit()
}

//默认 ""
fun getString(key: String): String {
    return sp.getString(key, "")!!
}

//        Int数据
fun putInt(key: String, value: Int) {
    ed.putInt(key, value)
    ed.commit()
}

//        默认 0
fun getInt(key: String): Int {
    return sp.getInt(key, 0)
}

//        Long数据
fun putLong(key: String, value: Long) {
    ed.putLong(key, value)
    ed.commit()
}

//        默认 0
fun getLong(key: String): Long {
    return sp.getLong(key, 0)
}

//        删除key数据
fun remove(key: String) {
    ed.remove(key)
    ed.commit()
}

fun getServerAddress(): String {
    if (getString("SERVER_IP") == "") {
        putString("SERVER_IP", "10.232.1.118")
    }
    if (getString("SERVER_PORT") == "") {
        putString("SERVER_PORT", "9011")
    }
    return "http://" + getString("SERVER_IP") + ":" + getString("SERVER_PORT") + "/pda/"
}
/**
 * 上面是 --> ShardPreference工具类
 */
